﻿Imports Entities
Public Class FormaPagoDAL
    Public Shared Function Create(ByVal zObject As FORMAPAGOS) As FORMAPAGOS
        Try
            Using bd As New gas_gasdesuvecinoEntities
                bd.FORMAPAGOS.Add(zObject)
                bd.SaveChanges()
                Return zObject
            End Using
        Catch ex As Exception
            Return Nothing
        End Try
    End Function
    Public Shared Function List() As List(Of FORMAPAGOS)
        Try
            Using bd As New gas_gasdesuvecinoEntities
                Dim query = From rec In bd.FORMAPAGOS
                            Where rec.ACTIVO
                              Order By rec.DESCRIPCION Ascending
                            Select rec
                Return query.ToList

            End Using
        Catch ex As Exception
            Debug.Print("FormaPagoDAL.List: " + ex.Message)
            Return Nothing
        End Try
    End Function
    Public Shared Function Exist(ByVal zId As Long) As Boolean
        Try
            Using bd As New gas_gasdesuvecinoEntities
                Dim query = (From rec In bd.FORMAPAGOS
                            Where rec.FORMAPAGO = zId
                            Select rec).Count
                If query > 0 Then
                    Return True
                Else
                    Return False
                End If
            End Using
        Catch ex As Exception
            Return False
        End Try
    End Function
    Public Shared Function Delete(ByVal zId As Long) As Boolean
        Try
            Using bd As New gas_gasdesuvecinoEntities
                Dim del = (From rec In bd.FORMAPAGOS
                          Where rec.FORMAPAGO = zId
                          Select rec).Single

                del.ACTIVO = False
                bd.SaveChanges()
                Return True
            End Using
        Catch ex As Exception
            Return False
        End Try
    End Function
    Public Shared Function Update(ByVal zobject As FORMAPAGOS) As FORMAPAGOS
        Try
            Using bd As New gas_gasdesuvecinoEntities
                Dim del = (From rec In bd.FORMAPAGOS
                          Where rec.FORMAPAGO = zobject.FORMAPAGO
                          Select rec).SingleOrDefault

                del.ACTIVO = True
                del.DESCRIPCION = zobject.DESCRIPCION
                bd.SaveChanges()
                Return del
            End Using
        Catch ex As Exception
            Return Nothing
        End Try
    End Function
    Public Shared Function SearchById(ByVal zId As Long) As FORMAPAGOS
        Using bd As New gas_gasdesuvecinoEntities
            Dim query = From rec In bd.FORMAPAGOS
                            Where rec.FORMAPAGO = zId And rec.ACTIVO
                            Select rec

            Return query.SingleOrDefault
        End Using
    End Function
End Class
